package edu.pod.hoteishilton.facade;

import edu.pod.hoteishilton.control.HospedeControl;
import edu.pod.hoteishilton.control.HotelControl;
import edu.pod.hoteishilton.database.DatabaseInterface;
import edu.pod.hoteishilton.model.Hospede;
import edu.pod.hoteishilton.model.Hotel;
import edu.pod.hoteishilton.model.Reserva;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.HashMap;

public class Facade extends UnicastRemoteObject implements IFacade {

    private static DatabaseInterface dtb;

    public Facade(DatabaseInterface dtbI) throws RemoteException {
        if (dtb == null) {
            dtb = dtbI;
        }

    }

    @Override
    public void addHospede() throws RemoteException {
//        dtb.getDaoHospede().sayHelloDaoHospede();

        HospedeControl hospedeControl = new HospedeControl(dtb.getDaoHospede());
//        IHospedeControl hospedeControl = (IHospedeControl) new HospedeControl(dtb.getDaoHospede());
        hospedeControl.addHospede(new Hospede("Thiago", "12312312", null, null, null));
        System.out.println(" testeeee");

    }

    @Override
    public void sayHello() throws RemoteException {
        System.out.println("HELLO WORLD");
    }

    @Override
    public void addHospede(Hospede hospede) throws RemoteException {
        HospedeControl hospedeControl = new HospedeControl(dtb.getDaoHospede());
        hospedeControl.addHospede(hospede);
        System.out.println("Hospede " + hospede.getNome() + "adicionado com sucesso!");
    }

    @Override
    public void addHotel(Hotel hotel) throws RemoteException {
        HotelControl hotelControl = new HotelControl(dtb.getDaoHotel());
        hotelControl.addHotel(hotel);
        System.out.println("Hotel " + hotel.getEndereco() + "adicionado com sucesso!");
    }

    @Override
    public HashMap getHoteis() throws RemoteException {
        HotelControl hotelControl = new HotelControl(dtb.getDaoHotel());
        return hotelControl.getHoteis();
    }

    @Override
    public HashMap getHospedes() throws RemoteException {
        HospedeControl hospedeControl = new HospedeControl(dtb.getDaoHospede());
        return hospedeControl.getHospedes();
    }

    @Override
    public Hotel getHotel(String apelido) throws RemoteException {
        HotelControl hotelControl = new HotelControl(dtb.getDaoHotel());
        return hotelControl.getHotel(apelido);
    }

    @Override
    public HashMap getReservas(String apelido) throws RemoteException {
        HotelControl hotelControl = new HotelControl(dtb.getDaoHotel());
        return hotelControl.getReservas(apelido);
    }

    @Override
    public Hospede getHospede(String cpf) throws RemoteException {
        HospedeControl hospedeControl = new HospedeControl(dtb.getDaoHospede());
        return hospedeControl.getHospede(cpf);
    }
}
